/*
 * @Description: 复制工具
 * @Author:
 * @Date:
 * @LastEditors: denghong
 */

import { Message } from "element-ui"
import Clipboard from 'clipboard'


/**
 * @param text 文本目标
 * @param event 事件源
 *  */
export default function handleClipboard(text, event) {
  const clipboard = new Clipboard(event.target, {
    text: () => text
  })

  clipboard.on('success', () => {
    Message({
      message: 'Copy successfully',
      type: 'success',
      duration: 1500
    })
    clipboard.destroy()
  })

  clipboard.on('error', () => {
    Message({
      message: 'Copy failed',
      type: 'error'
    })
    clipboard.destroy()
  })
  clipboard.onClick(event)
}
